package com.qingchuan.service.impl;

import com.qingchuan.enums.GraphTypeEnum;
import com.qingchuan.service.DrawGraphService;
import com.qingchuan.strategy.BasicGraphStrategy;
import com.qingchuan.strategy.context.GraphContextStrategy;
import com.qingchuan.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author m17610881257@163.com
 * @version : DrawGraphServiceImpl.java, v 0.1 2022-05-25 10:05 m17610881257@163.com Exp $$
 * @Description 实现类
 */
@Slf4j
@Service
public class DrawGraphServiceImpl implements DrawGraphService {

    @Autowired
    private GraphContextStrategy graphContextStrategy;

    @Override
    public String draw(Integer graphCode) {
        List<String> graphList = (List<String>) SpringUtils.getBean("getAndAddGraphList");
        String graph = GraphTypeEnum.getBeanNameByCode(graphCode);
        if (graph == null) {
            return "没有查询到基本图形，传入的基本图形code码可能有误!";
        }
        String draw = graphContextStrategy.draw(graph);
        // 将当前绘制的图形添加到画布容器中
        graphList.add(GraphTypeEnum.getGraphNameByCode(graphCode));
        log.info("当前已绘制的图形:{}", graphList);
        return draw;
    }
}
